#include <bits/stdc++.h>

using namespace std;

class Spreadsheet
{
private:
    vector<vector<int>> grid;
    int rows;

public:
    pair<int, int> getColRow(const string &cell)
    {
        int col = cell[0] - 'A';
        int row = stoi(cell.substr(1)) - 1;
        return {row, col};
    }
    Spreadsheet(int rows) : rows(rows)
    {
        grid.resize(rows, vector<int>(26, 0));
    }

    void setCell(string cell, int value)
    {
        auto [row, col] = getColRow(cell);
        grid[row][col] = value;
    }

    void resetCell(string cell)
    {
        setCell(cell, 0);
    }

    int getValue(string formula)
    {
        if (formula[0] == '=')
        {
            formula = formula.substr(1);
            int plusPos = formula.find('+');
            string left = formula.substr(0, plusPos);
            string right = formula.substr(plusPos + 1);

            int leftValue = isdigit(left[0]) ? stoi(left) : getCellValue(left);
            int rightValue = isdigit(right[0]) ? stoi(right) : getCellValue(right);

            return leftValue + rightValue;
        }
        return stoi(formula);
    }

    int getCellValue(const string &cell)
    {
        auto [row, col] = getColRow(cell);
        return grid[row][col];
    }
};

/**
 * Your Spreadsheet object will be instantiated and called as such:
 * Spreadsheet* obj = new Spreadsheet(rows);
 * obj->setCell(cell,value);
 * obj->resetCell(cell);
 * int param_3 = obj->getValue(formula);
 */

